package com.wdd.recoveryvehicle.mapper;

import com.wdd.recoveryvehicle.employeeUser.bean.EmpInfoVB;
import com.wdd.recoveryvehicle.employeeUser.bean.EmpTypeVB;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 客户人员
 *
 * @author globalMr
 */
@Repository
@Mapper
public interface EmployeeMapper {

    /**
     * 插入 数据信息
     *
     * @param empInfoVB
     * @return
     */
    @Insert(" insert into emp_info set " +
            " emp_id = #{empInfoVB.emp_id}, emp_name = #{empInfoVB.emp_name}, emp_sex = #{empInfoVB.emp_sex}, emp_idcard = #{empInfoVB.emp_idcard}, emp_phone = #{empInfoVB.emp_phone}, " +
            " emp_email = #{empInfoVB.emp_email}, emp_company = #{empInfoVB.emp_company}, office_phone = #{empInfoVB.office_phone}, emp_start = #{empInfoVB.emp_start}, emp_type = #{empInfoVB.emp_type}, " +
            " remark = #{empInfoVB.remark}, create_time = now(), create_company = #{company_id}, create_user = #{user_id} ")
    boolean insertEmpInfo(@Param("empInfoVB") EmpInfoVB empInfoVB, @Param("user_id") String user_id, @Param("company_id") String company_id);

    /**
     * 查询 客户数据信息
     *
     * @param useful
     * @return
     */
    @Select(" select emp_id, emp_name, emp_sex, emp_idcard, emp_phone, " +
            " emp_email, emp_company, office_phone, emp_start, emp_type, " +
            " create_time, remark " +
            " from emp_info " +
            " where useful = #{useful} and create_company = #{company_id} " +
            " order by emp_start asc, create_time desc ")
    List<EmpInfoVB> selectEmpInfoVBByUseful(@Param("useful") String useful, @Param("company_id") String company_id);

    /**
     * 查询 客户数据信息
     *
     * @param emp_id
     * @return
     */
    @Select(" select emp_id, emp_name, emp_sex, emp_idcard, emp_phone, " +
            " emp_email, emp_company, office_phone, emp_start, emp_type, " +
            " create_time, remark " +
            " from emp_info " +
            " where useful = 1 and emp_id = #{emp_id} " +
            " order by emp_start asc, create_time desc ")
    EmpInfoVB selectEmpInfoVBByEmpId(@Param("emp_id") String emp_id);

    /**
     * 查询 公司的人员数据 --- 有效
     * @param create_company
     * @return
     */
    @Select(" select emp_id, emp_name, emp_phone" +
            " from emp_info" +
            " where useful = 1 and create_company = #{create_company} ")
    List<EmpInfoVB> selectEmpIdNamePhone(@Param("create_company") String create_company);

    /**
     * 查询 客户id --- vehicle_id
     *
     * @param vehicle_id
     * @return
     */
    @Select(" select emp_id from emp_vehicle_relation where vehicle_id = #{vehicle_id} and useful = 1 ")
    List<String> selectEmpIdsByVehicleId(@Param("vehicle_id") String vehicle_id);

    /**
     * 查询 客户类型
     *
     * @return
     */
    @Select(" select type_id, type_name from emp_type where useful = 1 ")
    List<EmpTypeVB> selectEmpTypeVB();

    /**
     * 查询 客户类型 --- 类型id
     *
     * @param type_id
     * @return
     */
    @Select(" select type_id, type_name from emp_type where type_id = #{type_id} and useful = 1 ")
    EmpTypeVB selectEmpTypeVBByTypeId(@Param("type_id") String type_id);

    /**
     * 负责人 负责的车牌号
     * @param emp_id
     * @return
     */
    @Select(" select vehi.vehicle_cph from emp_vehicle_relation empve " +
            " join vehicle_info vehi on vehi.vehicle_id = empve.vehicle_id " +
            " where empve.emp_id = #{emp_id} and empve.useful = 1 ")
    List<String> selectCountEmpVehicle(@Param("emp_id") String emp_id);

    /**
     * 更新 数据信息
     *
     * @param empInfoVB
     * @return
     */
    @Update(" update emp_info " +
            " set emp_name = #{empInfoVB.emp_name}, emp_sex = #{empInfoVB.emp_sex}, emp_idcard = #{empInfoVB.emp_idcard}, emp_phone = #{empInfoVB.emp_phone}, emp_email = #{empInfoVB.emp_email}, " +
            " emp_company = #{empInfoVB.emp_company}, office_phone = #{empInfoVB.office_phone}, emp_start = #{empInfoVB.emp_start}, emp_type = #{empInfoVB.emp_type}, " +
            " remark = #{empInfoVB.remark}, update_time = now(), update_user = #{user_id} " +
            " where emp_id = #{empInfoVB.emp_id} ")
    boolean updateEmpInfoVB(@Param("empInfoVB") EmpInfoVB empInfoVB, @Param("user_id") String user_id);

    /**
     * 更新 数据信息为无效
     *
     * @param emp_id
     * @return
     */
    @Update(" update emp_info set useful = 0, update_time = now(), update_user = #{user_id} " +
            " where emp_id = #{emp_id} ")
    boolean updateEmpInfoUsefulWx(@Param("emp_id") String emp_id, @Param("user_id") String user_id);


}
